package eg.backend.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.datanucleus.jpa.annotations.Extension;

import eg.backend.base.GoalStatus;

@Entity
@NamedQueries({
	@NamedQuery(name = "Goal.findByUser", query = "select t from eg.backend.domain.Goal t where t.owner = :user"),
	@NamedQuery(name = "Goal.findByUserAndStatus", query = "select t from eg.backend.domain.Goal t where t.owner = :user and t.status = :status")
})
public class Goal {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String encodedKey;
	private String name;

	private String owner;
	
	//ignore joining a goal for now
//	@ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST })
//	@JoinTable(name = "goal_joiner", joinColumns = @JoinColumn(name = "goal_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "joiner_id", referencedColumnName = "id"))
//	private List<User> joiners = new ArrayList<User>();
	
	@Enumerated(EnumType.STRING)
	private GoalStatus status;
	
	private Date createdTime;
	
	private Set<String> budgets = new HashSet<String>();

	public String getEncodedKey() {
		return encodedKey;
	}

	public void setEncodedKey(String encodedKey) {
		this.encodedKey = encodedKey;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public Set<String> getBudgets() {
		return budgets;
	}

	public void setBudgets(Set<String> budgets) {
		this.budgets = budgets;
	}

	public GoalStatus getStatus() {
		return status;
	}

	public void setStatus(GoalStatus status) {
		this.status = status;
	}

	public Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(Date createdTime) {
		this.createdTime = createdTime;
	}
}
